package db_live

import (
	global2 "longmen/server/config/global"
	"longmen/server/pkg/protobuf"
)

func LiveStore(page int, size int) ([]*protobuf.LiveStore, int64, error) {
	var (
		err   error
		total int64
		res   []*protobuf.LiveStore
	)

	if size <= 0 || size >= 20 {
		size = 20
	}

	err = global2.Live().Table("db_live_store").Where("status=1").Count(&total).Limit(size).Offset((page - 1) * size).Order("sort asc").Scan(&res).Error
	if err != nil {
		return nil, total, err
	}

	return res, total, nil
}

func LiveStoreOrderList(uid int, page int, size int) ([]*protobuf.LiveStoreOrderList, int64, error) {
	var (
		err   error
		total int64
		res   []*protobuf.LiveStoreOrderList
	)

	if size <= 0 || size >= 20 {
		size = 20
	}

	err = global2.Live().Table("db_live_store_order").Where("uid=?", uid).Count(&total).Limit(size).Offset((page - 1) * size).Order("id desc").Scan(&res).Error
	if err != nil {
		return nil, total, err
	}

	return res, total, nil
}
